package com.hnkywl.jip.action;

import com.hnkywl.jip.service.CustomerService;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 说明：
 * 包:        com.hnkywl.jip.action
 * 类描述:    [一句话描述该类的功能]
 * 创建人:    ZHUCHG
 * 创建时间: 13-3-2 上午11:11
 * 修改人:    ZHUCHG
 * 修改时间: 13-3-2 上午11:11
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/cfg")
public class CustomerAction extends SimpleActionSupport {
    private Integer companyId;
    private Integer customerId;
    private String code;

    private String key;

    private Integer limit;
    private Integer start;

    private List<Object[]> companyList;
    private List<Object[]> customerList;

    private Page<Object[]> gridResult;

    private CustomerService customerService;

    @Action("customer_mapping")
    public String customerMapping() {
        companyList = customerService.findCompany();
        return SUCCESS;
    }

    @Action("customer_grid_json")
    public String customerGridJson() {
        gridResult = customerService.findCustomer(companyId, customerId, code, limit, start);
        return SUCCESS;
    }

    @Action("save_customer_mapping")
    public void saveCustomerMapping() {
        try {
            customerService.saveCustomerMapping(companyId, customerId, code);
            renderJson("{\"success\":true,\"message\":\"保存成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"success\":true,\"message\":\"" + e.getMessage() + "\"}");
        }
    }


    //================getter==================
    public Page<Object[]> getGridResult() {
        return gridResult;
    }

    public List<Object[]> getCustomerList() {
        return customerList;
    }

    public List<Object[]> getCompanyList() {
        return companyList;
    }

    //==================setter====================
    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    @Autowired
    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }
}
